package cn.csxw.openchina.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.csxw.openchina.R;
import cn.csxw.openchina.entity.DrawerMenuBean;

/**
 * 侧边栏菜单的Adapter
 */

public class DrawerMenuAdapter extends BaseAdapter {
    private List<DrawerMenuBean> mMenuBeenList = new ArrayList<>();
    private Context mContext;
    public DrawerMenuAdapter(Context mContext, List<DrawerMenuBean> mMenuBeenList) {
        this.mMenuBeenList = mMenuBeenList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mMenuBeenList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = null;
        TextView textView = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.view_drawer_menu,null);
            imageView =  (ImageView) convertView.findViewById(R.id.iv_drawer_menu);
            textView = (TextView) convertView.findViewById(R.id.tv_drawer_menu_title);
        }
        DrawerMenuBean menuBean = mMenuBeenList.get(position);
        if(menuBean!=null){
            if(imageView!= null){
                imageView.setImageResource(menuBean.getDrawable());
                textView.setText(menuBean.getTitle());
            }
        }
        return convertView;
    }

    /**
     * 提供设置adapter的数据的方法
     * @param mMenuBeenList
     */
    public void setDate(List<DrawerMenuBean> mMenuBeenList){
        this.mMenuBeenList = mMenuBeenList;
        notifyDataSetChanged();
    }
}
